{# Copyright The IETF Trust 2025, All Rights Reserved #}
{% extends "group/group_base.html" %}
{% load origin static %}
{% block title %}
    Meetings
    {% if group %}for {{ group.acronym }}{% endif %}
{% endblock %}
{% block buttonlist %}
    {{ block.super }}
    <a class="btn btn-primary"
       href="{% url 'ietf.meeting.views.meeting_requests' %}">Session requests</a>
    {% if can_edit or can_always_edit %}
        <a class="btn btn-primary" href="{% url 'ietf.meeting.views_session_request.list_view' %}">Request a session</a>
        <a class="btn btn-primary"
           href="{% url 'ietf.meeting.views.interim_request' %}?group={{ group.id }}">
            Request an interim meeting
        </a>
    {% endif %}
{% endblock %}
{% block group_content %}
    {% origin %}
    {% include "meeting/tz-display.html" with meeting_timezone=None id_suffix="" minimal=False only %}
    {% if in_progress %}
        <h2 class="mt-5" id="inprogressmeets">Meetings in progress</h2>
        {% with sessions=in_progress show_request=True show_ical=True can_edit_materials=can_edit %}
            <table class="table table-sm table-striped tablesorter">
                <thead>
                    <tr>
                        <th class="col-3" scope="col" data-sort="meeting">Meeting</th>
                        <th class="col-3" scope="col" data-sort="date">Date</th>
                        <th scope="col"></th>
                        <th scope="col">Materials</th>
                    </tr>
                </thead>
                <tbody>
                    {% include "group/meetings-row.html" %}
                </tbody>
            </table>
        {% endwith %}
    {% endif %}
    {% if future %}
        <h2 class="mt-5" id="futuremeets">
            Future Meetings
            {% for cal_action in cal_actions %}
                <a class="btn btn-primary"
                   href="{{ cal_action.url }}">
                    {{ cal_action.label }}
                </a>
            {% endfor %}
        </h2>
        <table class="table table-sm table-striped tablesorter">
            <thead>
                <tr>
                    <th class="col-3" scope="col" data-sort="meeting">Meeting</th>
                    <th class="col-3" scope="col" data-sort="date">Date</th>
                    <th scope="col"></th>
                    <th scope="col">Materials</th>
                </tr>
            </thead>
            {% with sessions=future show_request=True show_ical=True can_edit_materials=can_edit %}
                <tbody>
                    {% include "group/meetings-row.html" %}
                </tbody>
            {% endwith %}
        </table>
    {% endif %}
    {% if past or recent %}
        <h2 class="mt-5" id="pastmeets">Past Meetings (within the last four years)</h2>
        <table class="table table-sm table-striped tablesorter">
            <thead>
                <tr>
                    <th class="col-3" scope="col" data-sort="meeting">Meeting</th>
                    <th class="col-3" scope="col" data-sort="date">Date</th>
                    <th scope="col"></th>
                    <th scope="col">Materials</th>
                </tr>
            </thead>
            <tbody>
                {% with sessions=recent can_edit_materials=can_edit %}
                    {% include "group/meetings-row.html" %}
                {% endwith %}
                {% with sessions=past can_edit_materials=False %}
                    {% include "group/meetings-row.html" %}
                {% endwith %}
            </tbody>
        </table>
    {% endif %}
    {# The following is a temporary performance workaround, not long term design #}
    {% if group.acronym != "iab" and group.acronym != "iesg" %}
        <p class="alert alert-info my-3">
            This page shows meetings within the last four years. For earlier meetings, please see the
            <a href="https://www.ietf.org/how/meetings/past/">proceedings</a>.
        </p>
    {% else %}
        {% comment %}
            Note: This block is only capable of correctly processing interim sessions.
            If the view starts sending other types of meetings with a non-empty 
            older_sessions value, this block will need to be adjusted.
        {% endcomment %}
        {% if far_past %}
            <h2 class="mt-5" id="farpastmeets">Meetings more than four years ago</h2>
            <table class="table table-sm table-striped tablesorter">
                <thead>
                    <tr>
                        <th class="col-3" scope="col" data-sort="meeting">Meeting</th>
                        <th class="col-3" scope="col" data-sort="date">Date</th>
                        <th scope="col"></th>
                        <th scope="col">Materials</th>
                    </tr>
                </thead>
                <tbody>
                    {% for s in far_past %}
                    <tr>
                        <td>
                            {% if s.meeting.type.slug == 'ietf' %}
                                IETF {{ s.meeting.number }}
                            {% else %}
                                {{ s.meeting.number }}
                            {% endif %}                    </td>
                        <td>
                            {% if s.current_status == "sched" %}
                                {{ s.time|date:"Y-m-d" }}
                            {% else %}
                                <i>{{ s.current_status_name }}</i>
                            {% endif %}
                        </td>
                        <td>
                            {% if s.name %}{{ s.name }}{% endif %}
                        </td>
                        <td>
                            {% if s.current_status == "sched" %}{{ s.time|date:"D" }}{% endif %}
                        </td>
                        <td>
                            {% if not s.canceled %}
                                <a class="btn btn-sm {% if not s.agenda %}btn-secondary disabled{% else %}btn-primary{% endif %}"
                                {% if s.agenda %}href="{{ s.agenda.get_absolute_url }}"{% endif %}>
                                    Agenda
                                </a>
                                <a class="btn btn-sm {% if not s.minutes %}btn-secondary disabled{% else %}btn-primary{% endif %}"
                                {% if s.minutes %}href="{{ s.minutes.get_absolute_url }}"{% endif %}>
                                    Minutes
                                </a>
                                {% if group.acronym == "iesg" %}
                                <a class="btn btn-sm {% if not s.narrative_minutes %}btn-secondary disabled{% else %}btn-primary{% endif %}"
                                {% if s.narrative_minutes %}href="{{ s.narrative_minutes.get_absolute_url }}"{% endif %}>
                                    Narrative Minutes
                                </a>                                
                                {% endif %}
                                <a class="btn btn-primary btn-sm"
                                    href="{% url 'ietf.meeting.views.session_details' num=s.meeting.number acronym=s.group.acronym %}">
                                    {% if can_always_edit or can_edit_materials %}
                                        <i class="bi bi-pencil-square">
                                        </i>
                                    {% endif %}
                                    Materials
                                </a>
                            {% endif %}
                        </td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        {% endif %}
    {% endif %}
{% endblock %}
{% block js %}
    <script src="{% static 'ietf/js/list.js' %}"></script>
    <script src="{% static 'ietf/js/moment.js' %}"></script>
    <script src="{% static 'ietf/js/upcoming.js' %}"></script>
    <script src="{% static 'ietf/js/timezone.js' %}"></script>
    <script>
    $(function () {
            // Init with best guess at local timezone.
            ietf_timezone.set_tz_change_callback(timezone_changed);
            ietf_timezone.initialize('local');
    });
    </script>
{% endblock %}
